var express = require("express");
var router = express.Router();
const puppeteer = require("puppeteer");

router.get("/list", async (req, res) => {
  // 启动浏览器

  let browser = await puppeteer.launch({
    // devtools: true,
    // slowMo: 1000,
    headless: false,
    args: ["--start-maximized"],
    defaultViewport: null,
  });

  // 创建一个新页面
  const page = await browser.newPage();

  // 访问一个网址
  try {
    await page
      .goto("https://www.yjpoo.com/ai-image/", { timeout: 6000 })
      .catch(() => {});
  } catch (error) {}

  const hrefs = await page.$$eval(".line-big > div > a", (el) =>
    el.map((x) => x.getAttribute("href"))
  );

  res.send(hrefs);
});

module.exports = router;
